<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
      
    <ui:composition template="/new-template/template-crud.xhtml">
    	
    	<ui:define name="tituloPagina">
    		<h:outputText value="Endereçamentos :: ZPE" />
    	</ui:define>
    	
    	<ui:define name="parametros">
    	   <ui:param name="bean" value="#{enderecamentoBean}" />
    	</ui:define>
    	
    	<ui:define name="tituloFieldSetFiltro">
		   <h:outputText value="&nbsp; Pesquisa Endereçamento &nbsp;" />
		</ui:define>
		
		<ui:define name="camposFiltro">
			<h:panelGrid columns="2" columnClasses="colunaBusca">
				 				  	
			</h:panelGrid>
		</ui:define>
		
		<ui:define name="tituloPainel">
		  <ui:param name="tituloPainel" value="Transação" />
		</ui:define>
		
		<ui:define name="resultFiltro">
			<p:dataTable align="center" 
   						 width="600px" 
   						 id="locais"
   						 rows="10"
   						 pageLinks="3"
   						 paginatorAlwaysVisible="false"
   						 emptyMessage="Nenhum endereçamento encontrado."
   						 value="#{bean.resultSearch}" 
       					 var="l" 
       					 paginator="#{bean.resultSearch.rowCount > 0}"
       					 paginatorPosition="bottom"
       					 rowStyleClass="bgLinha1,bgLinha2">
       					
       						<p:column headerText="" style="width:40px; text-align:center;">
       							<div class="colunaAcao">					    			
									<h:commandButton style="border:none;" 
													 id="cmdUpd" 
													 image="#{resource['img:ico_edit.gif']}"
													 actionListener="#{bean.prepareUpdate}">
										  <p:ajax update="painelGlobal" />
									</h:commandButton>
								</div> 
       						</p:column>
       						
       						<p:column headerText="ID" style="text-align:center;width:30px">
       							<h:outputText value="#{l.id}" />
       						</p:column>
       						
       						<p:column headerText="Carga" style="text-align:center;">
       							<h:outputText value="#{l.carga.codigo}" />
       						</p:column>
       						
       						<p:column style="width:60px; text-align:center;">
       							<f:facet name="header">
       								<h:selectBooleanCheckbox styleClass="ui-checkBoxMain" rendered="#{bean.resultSearch.rowCount > 0}" />
       							</f:facet>
       							<h:selectBooleanCheckbox styleClass="ui-checkBox" valueChangeListener="#{bean.select}" />
       						</p:column>
       						
				 	</p:dataTable> 
		</ui:define>
		
		<ui:define name="tituloFieldSetInsert">
		  <h:outputLabel value="&nbsp; Novo Endereçamento" />
		</ui:define>
		
		<ui:define name="camposInsert">
			<h:panelGrid columns="6" columnClasses="colunaBusca" >
			
			  <h:outputLabel value="Código:"/>
			  <h:inputText label="Código" 
						  readonly="true" 
						  style="background-color:#CCC"
						   value="#{bean.entity.id}" 
						   maxlength="50" 
						   size="20">						
			  </h:inputText>
			  
			  <h:outputLabel value="Data de Movimentação:"/>	
			  <h:inputText required="true" readonly="true" style="background-color:#CCC"
						   label="Data de Movimentação"
						   value="#{bean.enderecamentoHistorico.dataMovimentacao}"
						   maxlength="50" 
						   size="20">
						   <f:convertDateTime pattern="dd/MM/yyyy HH:mm"/> 						
			  </h:inputText>
			  
			  <h:outputLabel value="Localização:"/>
			  <h:inputText required="true" readonly="true" style="background-color:#CFCFCF"
						   label="Nome" id="localizacao"
						   value="#{bean.enderecamentoHistorico.localizacao}" 
						   maxlength="50"    
						   size="20">						
			  </h:inputText> 
			  
			  <h:outputLabel value="Carga: *"/>
			  <h:column>
				  <h:inputText required="true" readonly="true"
							   label="Código"
							   value="#{bean.entity.carga.codigo}" 
							   maxlength="50" 
							   size="20">						  
				  </h:inputText> 
				  <p:commandButton value="..." style="width:35px;height:24px" process="@this"  
								   actionListener="#{bean.findCargas}"   
								   update="pnlModals" />	
			  </h:column>
			  
			  <h:outputLabel value="CE:"/> 
			  <h:inputText required="true" 
						   label="Código"
						   readonly="true"
						   value="#{bean.entity.carga.numeroCE}" 
						   maxlength="50" 
						   size="20">						
			  </h:inputText>
			  
			  <h:outputLabel value="Acondicionamento:"/>
			  <h:inputText required="true" 
						   label="Código"
						   readonly="true"
						   value="#{bean.entity.carga.acondicionamento}" 
						   maxlength="50" 
						   size="20">						
			  </h:inputText>  
			  
			  <h:outputLabel value="Local: *"/>  
			  <h:selectOneMenu id="locais" label="Local" value="#{bean.enderecamentoHistorico.local}" style="width:149px" converter="converterEntity">
			  	<f:selectItem itemLabel="--" itemValue="#{null}"></f:selectItem>
			  	<f:selectItems value="#{bean.locais}"></f:selectItems>
			  </h:selectOneMenu>
			  
			  <h:outputLabel value="Quantidade:"/>
			  <h:inputText required="false" 
							 label="Quantidade"
							 id="quantidade"
							 readonly="#{!((bean.entity.conteiner == null) or (bean.entity.conteiner.id == null))}"
							 value="#{bean.entity.quantidade}"
							 size="20">  
              </h:inputText>  
			  
			  <h:outputLabel value="Contêiner: *"/>
			  <h:selectOneMenu id="conteiners" label="Contêiner" value="#{bean.entity.conteiner}" style="width:149px" converter="converterEntity">
			  	<f:selectItem itemLabel="--" itemValue="#{null}"></f:selectItem>
			  	<f:selectItems value="#{bean.conteiners}"></f:selectItems>
			  	<f:ajax event="change" onclick="carregando.show();" listener="#{bean.selecionaContainer}" oncomplete="carregando.hide();"  render="quantidade" execute="conteiners" />
			  </h:selectOneMenu>
			  
		  </h:panelGrid>
		  <h:panelGrid id="gridLocalizacao" columns="8" columnClasses="colunaBusca" >
		  	  <h:outputLabel value="Bloco: *"/>
			  <h:selectOneMenu id="blocos" label="Bloco" value="#{bean.enderecamentoHistorico.bloco}" style="width:60px">
			  	<f:selectItem itemLabel="--" itemValue="#{null}"></f:selectItem>
			  	<f:selectItems value="#{bean.blocos}"></f:selectItems>
			  	<f:ajax event="change" onclick="carregando.show();" oncomplete="carregando.hide();"  render="localizacao" execute="blocos" />
			  </h:selectOneMenu>  
			    
			  <h:outputLabel value="Linha: *"/>
			  <h:selectOneMenu id="linhas" label="Linha" value="#{bean.enderecamentoHistorico.linha}" style="width:60px">
			  	<f:selectItem itemLabel="--" itemValue="#{null}"></f:selectItem>
			  	<f:selectItems value="#{bean.linhas}"></f:selectItems>
			  	<f:ajax event="change" onclick="carregando.show();" oncomplete="carregando.hide();"  render="localizacao" execute="alturas" />
			  </h:selectOneMenu>
			   
			  <h:outputLabel value="Altura: *"/> 
			  <h:selectOneMenu id="alturas" label="Altura" value="#{bean.enderecamentoHistorico.altura}" style="width:60px">
			  	<f:selectItem itemLabel="--" itemValue="#{null}"></f:selectItem> 
			  	<f:selectItems value="#{bean.alturas}"></f:selectItems>
			  	<f:ajax event="change" onclick="carregando.show();" oncomplete="carregando.hide();"  render="localizacao" execute="linhas" />
			  </h:selectOneMenu> 
			   
			  <h:outputLabel value="Coluna: *"/>
			  <p:inputText required="false" 
							 label="Coluna" id="coluna"
							 value="#{bean.enderecamentoHistorico.coluna}"
							 size="20">
                        	 <f:ajax event="blur" onclick="carregando.show();" oncomplete="carregando.hide();"  render="localizacao" execute="linhas" />
              </p:inputText>
			  
		  </h:panelGrid>
		  
		  <p:commandButton styleClass="btIcon" 
											 value="Adicionar"
											 image="saveIcon" 
											 actionListener="#{bean['adicionarEnderecamento']}"
											 update="painelGlobal" />
		  
		  <br /><br /> 
		  
		  <p:panel header="Histórico de Movimentações">
		  		<p:dataTable id="dataTableMovimentacoes" align="center" value="#{bean.enderecamentoDataModel}" var="var" emptyMessage="Carga sem movimentações!">
		  			<p:column headerText="ID" style="text-align:center;width:30px">
       					<h:outputText value="#{var.id}" />
       				</p:column>
       						
       				<p:column headerText="Carga" style="text-align:center;">
       					<h:outputText value="#{var.enderecamento.carga.codigo}" />
       				</p:column>
		  		</p:dataTable>
		  </p:panel>
		  
		  <h:panelGroup id="pnlModals">
		  		<p:dialog id="panelCargaID" width="600" header="Pesquisar Carga"
						widgetVar="panelCarga" fixedCenter="true" showEffect="fade" rendered="#{bean.cargasModal != null}"
						hideEffect="fade" visible="true" modal="true">
					
						<h:panelGrid columns="3">
							<h:outputLabel value="CE:"></h:outputLabel>
							<h:inputText value="#{bean.pesquisaModal}" id="pesquisaModal"></h:inputText>  
							<p:commandButton 
										value="Pesquisar" 
										styleClass="btIcon" 
										image="searchIcon"  
										process="@this pesquisaModal"   
										actionListener="#{bean.findCargasByCE}" 
										update="dataTableCargas" />	
						</h:panelGrid> 
						<br /> 
						<p:dataTable id="dataTableCargas" align="center" value="#{bean.cargasModal}" var="var" emptyMessage="Nenhuma Carga encontrada!">
			       					
							<p:column headerText="Código" style="text-align:center;width:100px">
								<h:outputText value="#{var.codigo}" />
							</p:column>
							
							<p:column headerText="CE" style="text-align:center;" >
								<h:outputText value="#{var.numeroCE}" />
							</p:column>
	
							<p:column headerText=" " style="text-align:center;width:50px" >
								<p:commandButton value="Selecionar" actionListener="#{bean.selecionaCarga}" 
									process="@this" onclick="panelCarga.hide()" 
									update=":formCadastro" />
							</p:column>
						</p:dataTable>
					
				</p:dialog>
		  </h:panelGroup>

		</ui:define>
		
						  	<div class="margemtop">
				  		<ui:insert name="botoesInsert">
				  			<p:commandButton styleClass="btIcon" 
											 value="Salvarrrr"
											 image="saveIcon" 
											 actionListener="#{bean['save']}" 
											 rendered="#{bean['inserting']}" 
											 oncomplete="mensagemAviso.show();"
											 update="painelGlobal" />
						
							<p:commandButton styleClass="btIcon" 
						 					 value="Atualizar"
											 image="updateIcon" 
								             actionListener="#{bean['update']}"
								 			 oncomplete="mensagemAviso.show();" 
											 rendered="#{bean['editing']}" 
											 update="painelGlobal" />
						
							<p:commandButton styleClass="btIcon" 
											 value="Voltar"
											 image="backIcon" 
											 actionListener="#{bean['cancel']}" 
											 immediate="true" 
											 update="painelGlobal" />
				  		</ui:insert>
					</div>
		
		
    </ui:composition>
</html>